<?php namespace app\admin\controller;
use system\model\Base;
use houdunwang\route\Controller;
use houdunwang\wechat\WeChat;
use houdunwang\config\Config;

class WeiXinValid extends Controller
{
	//动作
	public function index ()
	{

		//var_dump(Config::get('wechat.cache_path'));die;
		//p(Config::get('wechat.token'));die;

		//验证请求
		(new WeChat())->valid();

		//消息管理模块
		$instance = WeChat::instance('message');
		$res = Base::find(1)->toArray()['base'];
//		p($res);die;

		$res = json_decode($res,true);

		p($res);
//关注用户扫描二维码事件

		if ($instance->isTextMsg())
		{
			$message  = $instance->getMessage();
			//向用户回复消息

			//file_put_contents('./aaaaa.php',v('config.huifu'));
			$instance->text($res['moren']);
		}


		//消息管理模块
		$instance = WeChat::instance('message');
		//判断是否是关注事件
		if ($instance->isSubscribeEvent())
		{
			//向用户回复消息
			$instance->text("感谢关注 纽斯比");
		}
	}


}
